package com.ssy.invoicing.mail.entity;

import java.util.Properties;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

/**
 * 邮件配置对象
 * <p>
 * 主要是邮件发送的一些配置信息
 * </p>
 * Comment of MailConfig
 * 
 * @author wb_suoyao.shen
 */
@Configuration
public class MailConfig {
    //从配置文件中读取相应的邮件配置属性
    @Value("${email.host}")
    private String emailHost;
    
    @Value("${email.username}")
    private String userName;
    
    @Value("${email.password}")
    private String password;
    
    @Value("${email.smtp.auth}")
    private String mailAuth;

    //JavaMailSender用来发送邮件的类
    @Bean
    public JavaMailSender mailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost(emailHost);
        mailSender.setUsername(userName);
        mailSender.setPassword(password);
        Properties pro = new Properties();
        pro.setProperty("mail.smtp.auth", mailAuth);
        mailSender.setJavaMailProperties(pro);
        return mailSender;
    }
}
